package es.ucm.is.www.GUI.client.panels;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.WindowResizeListener;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.RootPanel;

import es.ucm.is.www.GUI.client.Root;
/**
 * <p>Title: PanelWaiting.java </p>
 *
 * <p>Description: Panel de espera que aparece ala hora de </p>
 *
 * <p>Copyright: </p>
 *
 * @author 
 * @version 1.0
 * @see
 */
public class PanelWaiting{
	
	private Image loading;
	private PopupPanel element;
	private AbsolutePanel panel;
	private WindowResizeListener listener;
	private Image imageExtra;
	/**
	 * Constructora de la clase
	 */
	public PanelWaiting(){
		panel = new AbsolutePanel();
		panel.setPixelSize(RootPanel.get().getOffsetWidth(), RootPanel.get().getOffsetHeight());
		panel.setStyleName("glass");
		Root.fondo = panel;
		element = new PopupPanel(false);		
		loading = new Image("ajax-loader.gif");
		element.setWidget(loading);
		listener = new WindowResizeListener(){

			public void onWindowResized(int width, int height) {
				element.setPopupPosition(width/2, height/2);
				
			}
			
		};
		Window.addWindowResizeListener(listener);
	}
	/**
	 * Metodo para mostrar el panel
	 */
	public void mostrar(){
		RootPanel.get().add(panel, 0, 0);
		//element.setPopupPosition(panel.getOffsetWidth()/2,panel.getOffsetWidth()/2);
		element.center();
	}
	/**
	 * Metodo para ocultar el panel
	 */
	public void ocultar(){
		element.hide();
		Window.removeWindowResizeListener(listener);
		RootPanel.get().remove(panel);
	}

}
